package com.sspro.simplertmp.core.encode;

import com.sspro.simplertmp.core.utils.Constant;
import com.wbapp.common.jni.JniProxy;

public class VideoEncodeFun {

    private int frameLen;
    private int mPreWidth;
    private int mPreHeight;
    private EncodeCallbackListener mEncodeCallbackListener;

    public VideoEncodeFun(int preWidth, int preHeight, EncodeCallbackListener listener) {
        mPreWidth = preWidth;
        mPreHeight = preHeight;
        mEncodeCallbackListener = listener;
        setFrameBuffers();
    }

    public void encodeFrame(byte[] data, boolean isRecording) {
        if (data == null) return;
        boolean result = false;
        if (isRecording) {
            result = JniProxy.m_CJniProxy.sendFrame(data, frameLen);
        } else {
            // TODO 硬编码（MediaCodec）
        }
        if (!result) {
            mEncodeCallbackListener.onVideoEncodeStatusCallback(Constant.EncodeErrorCode.SEND_FRAME_FAILED);
        }
    }

    public void setEncodeCallbackListener(EncodeCallbackListener listener) {
        mEncodeCallbackListener = listener;
    }

    private void setFrameBuffers() {
        frameLen = mPreWidth * mPreWidth * 3 / 2;
    }

}
